package com.boardour.socket.client;

import com.boardour.socket.foo.constants.TCPConstants;
import com.boardour.socket.listener.OnReceiveListener;
import com.boardour.socket.server.TCPServerPresenter;

import java.net.InetAddress;

public class WifiClientPresenter {
    private TCPClientPresenter client = new TCPClientPresenter();
    private TCPServerPresenter server = new TCPServerPresenter();


    public WifiClientPresenter(){
        start();
    }
    public TCPClientPresenter getClient() {
        return client;
    }


    public TCPServerPresenter getServer() {
        return server;
    }

    public void start() {
        server.start(TCPConstants.PORT_CLIENT);
    }

    public String getIp() {
        return server.getIp();
    }

    public void close() {
        client.close();
        server.close();
    }

    /**
     * 连接客户端
     */
    public void connectServer(InetAddress address) {
        client.connect(address, TCPConstants.PORT_SERVER);
    }

    /**
     * 连接客户端
     */
    public void connectServer(String ip) {
        client.connect(ip, TCPConstants.PORT_SERVER);
    }

    public void send(int trackIndex, byte[] data, long time) {
        client.send(trackIndex, data, time);
    }

    public void setOnReceiveListener(OnReceiveListener onReceiveListener) {
        server.setOnReceiveListener(onReceiveListener);
    }
}
